`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    19:48:01 11/24/2012 
// Design Name: 
// Module Name:    table_unit 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
	module table_unit(
   input [9:0]pixel_x_i,
	input [9:0]pixel_y_i,
	output [7:0]square_rgb_o,
	output square_white_on,
	output square_black_on
   );

	
	//840x640 hay que hacer el tablero de 640x640
	// Parametros constantes de posicion y tamano
	
	localparam POS_X = 0;
	localparam POS_Y = 0;
	localparam SQUARE_SIZE = 60;

	//Cuadro  Blanco
	localparam square_x_lB = POS_X;//0
	localparam square_x_rB = POS_X + SQUARE_SIZE;//80
	localparam square_y_lB = POS_Y;//0
	localparam square_y_rB = POS_Y + SQUARE_SIZE;//80
	
	//Cuadro Negro
	localparam square_x_lN = POS_X;
	localparam square_x_rN = POS_X + SQUARE_SIZE;
	localparam square_y_lN = POS_Y;
	localparam square_y_rN = POS_Y + SQUARE_SIZE;
	
	// Pixeles en pantalla que cubre la imagen
	assign square_black = ((pixel_x_i >= 0) && (pixel_x_i <= SQUARE_SIZE) && (pixel_y_i >= 0) && (pixel_y_i <= SQUARE_SIZE))
							    || ((pixel_x_i >= (2*SQUARE_SIZE)) && (pixel_x_i <= (3*SQUARE_SIZE)) && (pixel_y_i >= 0) && (pixel_y_i <= SQUARE_SIZE))
	                      || ((pixel_x_i >= (4*SQUARE_SIZE)) && (pixel_x_i <= (5*SQUARE_SIZE)) && (pixel_y_i >= 0) && (pixel_y_i <= SQUARE_SIZE))
								 || ((pixel_x_i >= (6*SQUARE_SIZE)) && (pixel_x_i <= (7*SQUARE_SIZE)) && (pixel_y_i >= 0) && (pixel_y_i <= SQUARE_SIZE))
								 //FILA 2
								 || ((pixel_x_i >= SQUARE_SIZE) && (pixel_x_i <= (2*SQUARE_SIZE)) && (pixel_y_i >= SQUARE_SIZE) && (pixel_y_i <= (2*SQUARE_SIZE)))
							    || ((pixel_x_i >= (3*SQUARE_SIZE)) && (pixel_x_i <= (4*SQUARE_SIZE)) && (pixel_y_i >= SQUARE_SIZE) && (pixel_y_i <= (2*SQUARE_SIZE)))
								 || ((pixel_x_i >= (5*SQUARE_SIZE)) && (pixel_x_i <= (6*SQUARE_SIZE)) && (pixel_y_i >= SQUARE_SIZE) && (pixel_y_i <= (2*SQUARE_SIZE)))
								 || ((pixel_x_i >= (7*SQUARE_SIZE)) && (pixel_x_i <= (8*SQUARE_SIZE)) && (pixel_y_i >= SQUARE_SIZE) && (pixel_y_i <= (2*SQUARE_SIZE)))
								 //FILA 3
								 || ((pixel_x_i >= 0) && (pixel_x_i <= SQUARE_SIZE) && (pixel_y_i >= (2*SQUARE_SIZE)) && (pixel_y_i <= (3*SQUARE_SIZE)))
								 || ((pixel_x_i >= (2*SQUARE_SIZE)) && (pixel_x_i <= (3*SQUARE_SIZE)) && (pixel_y_i >= (2*SQUARE_SIZE)) && (pixel_y_i <= (3*SQUARE_SIZE)))
								 || ((pixel_x_i >= (4*SQUARE_SIZE)) && (pixel_x_i <= (5*SQUARE_SIZE)) && (pixel_y_i >= (2*SQUARE_SIZE)) && (pixel_y_i <= (3*SQUARE_SIZE)))
								 || ((pixel_x_i >= (6*SQUARE_SIZE)) && (pixel_x_i <= (7*SQUARE_SIZE)) && (pixel_y_i >= (2*SQUARE_SIZE)) && (pixel_y_i <= (3*SQUARE_SIZE)))
								 //FILA 4
								 ||((pixel_x_i >= SQUARE_SIZE) && (pixel_x_i <= (2*SQUARE_SIZE)) && (pixel_y_i >= (3*SQUARE_SIZE)) && (pixel_y_i <= (4*SQUARE_SIZE)))
							    || ((pixel_x_i >= (3*SQUARE_SIZE)) && (pixel_x_i <= (4*SQUARE_SIZE)) && (pixel_y_i >= (3*SQUARE_SIZE)) && (pixel_y_i <= (4*SQUARE_SIZE)))
								 || ((pixel_x_i >= (5*SQUARE_SIZE)) && (pixel_x_i <= (6*SQUARE_SIZE)) && (pixel_y_i >= (3*SQUARE_SIZE)) && (pixel_y_i <= (4*SQUARE_SIZE)))
								 || ((pixel_x_i >= (7*SQUARE_SIZE)) && (pixel_x_i <= (8*SQUARE_SIZE)) && (pixel_y_i >= (3*SQUARE_SIZE)) && (pixel_y_i <= (4*SQUARE_SIZE)))
								 //FILA 5
								 || ((pixel_x_i >= 0) && (pixel_x_i <= SQUARE_SIZE) && (pixel_y_i >= (4*SQUARE_SIZE)) && (pixel_y_i <= (5*SQUARE_SIZE)))
								 || ((pixel_x_i >= (2*SQUARE_SIZE)) && (pixel_x_i <= (3*SQUARE_SIZE)) && (pixel_y_i >= (4*SQUARE_SIZE)) && (pixel_y_i <= (5*SQUARE_SIZE)))
								 || ((pixel_x_i >= (4*SQUARE_SIZE)) && (pixel_x_i <= (5*SQUARE_SIZE)) && (pixel_y_i >= (4*SQUARE_SIZE)) && (pixel_y_i <= (5*SQUARE_SIZE)))
								 || ((pixel_x_i >= (6*SQUARE_SIZE)) && (pixel_x_i <= (7*SQUARE_SIZE)) && (pixel_y_i >= (4*SQUARE_SIZE)) && (pixel_y_i <= (5*SQUARE_SIZE)))
								 //FILA 6
								 ||((pixel_x_i >= SQUARE_SIZE) && (pixel_x_i <= (2*SQUARE_SIZE)) && (pixel_y_i >= (5*SQUARE_SIZE)) && (pixel_y_i <= (6*SQUARE_SIZE)))
							    || ((pixel_x_i >= (3*SQUARE_SIZE)) && (pixel_x_i <= (4*SQUARE_SIZE)) && (pixel_y_i >= (5*SQUARE_SIZE)) && (pixel_y_i <= (6*SQUARE_SIZE)))
								 || ((pixel_x_i >= (5*SQUARE_SIZE)) && (pixel_x_i <= (6*SQUARE_SIZE)) && (pixel_y_i >= (5*SQUARE_SIZE)) && (pixel_y_i <= (6*SQUARE_SIZE)))
								 || ((pixel_x_i >= (7*SQUARE_SIZE)) && (pixel_x_i <= (8*SQUARE_SIZE)) && (pixel_y_i >= (5*SQUARE_SIZE)) && (pixel_y_i <= (6*SQUARE_SIZE)))
								 //FILA 7
								 || ((pixel_x_i >= 0) && (pixel_x_i <= SQUARE_SIZE) && (pixel_y_i >= (6*SQUARE_SIZE)) && (pixel_y_i <= (7*SQUARE_SIZE)))
								 || ((pixel_x_i >= (2*SQUARE_SIZE)) && (pixel_x_i <= (3*SQUARE_SIZE)) && (pixel_y_i >= (6*SQUARE_SIZE)) && (pixel_y_i <= (7*SQUARE_SIZE)))
								 || ((pixel_x_i >= (4*SQUARE_SIZE)) && (pixel_x_i <= (5*SQUARE_SIZE)) && (pixel_y_i >= (6*SQUARE_SIZE)) && (pixel_y_i <= (7*SQUARE_SIZE)))
								 || ((pixel_x_i >= (6*SQUARE_SIZE)) && (pixel_x_i <= (7*SQUARE_SIZE)) && (pixel_y_i >= (6*SQUARE_SIZE)) && (pixel_y_i <= (7*SQUARE_SIZE)))
								 //FILA 8
								 ||((pixel_x_i >= SQUARE_SIZE) && (pixel_x_i <= (2*SQUARE_SIZE)) && (pixel_y_i >= (7*SQUARE_SIZE)) && (pixel_y_i <= (8*SQUARE_SIZE)))
							    || ((pixel_x_i >= (3*SQUARE_SIZE)) && (pixel_x_i <= (4*SQUARE_SIZE)) && (pixel_y_i >= (7*SQUARE_SIZE)) && (pixel_y_i <= (8*SQUARE_SIZE)))
								 || ((pixel_x_i >= (5*SQUARE_SIZE)) && (pixel_x_i <= (6*SQUARE_SIZE)) && (pixel_y_i >= (7*SQUARE_SIZE)) && (pixel_y_i <= (8*SQUARE_SIZE)))
								 || ((pixel_x_i >= (7*SQUARE_SIZE)) && (pixel_x_i <= (8*SQUARE_SIZE)) && (pixel_y_i >= (7*SQUARE_SIZE)) && (pixel_y_i <= (8*SQUARE_SIZE)));
		

			assign square_white = ((pixel_x_i >= SQUARE_SIZE) && (pixel_x_i <= (2*SQUARE_SIZE)) && (pixel_y_i >= 0) && (pixel_y_i <= SQUARE_SIZE))
							    || ((pixel_x_i >= (3*SQUARE_SIZE)) && (pixel_x_i <= (4*SQUARE_SIZE)) && (pixel_y_i >= 0) && (pixel_y_i <= SQUARE_SIZE))
	                      || ((pixel_x_i >= (5*SQUARE_SIZE)) && (pixel_x_i <= (6*SQUARE_SIZE)) && (pixel_y_i >= 0) && (pixel_y_i <= SQUARE_SIZE))
								 || ((pixel_x_i >= (7*SQUARE_SIZE)) && (pixel_x_i <= (8*SQUARE_SIZE)) && (pixel_y_i >= 0) && (pixel_y_i <= SQUARE_SIZE))
								 //FILA 2
								 || ((pixel_x_i >= 0) && (pixel_x_i <= SQUARE_SIZE) && (pixel_y_i >= SQUARE_SIZE) && (pixel_y_i <= (2*SQUARE_SIZE)))
							    || ((pixel_x_i >= (2*SQUARE_SIZE)) && (pixel_x_i <= (3*SQUARE_SIZE)) && (pixel_y_i >= SQUARE_SIZE) && (pixel_y_i <= (2*SQUARE_SIZE)))
								 || ((pixel_x_i >= (4*SQUARE_SIZE)) && (pixel_x_i <= (5*SQUARE_SIZE)) && (pixel_y_i >= SQUARE_SIZE) && (pixel_y_i <= (2*SQUARE_SIZE)))
								 || ((pixel_x_i >= (6*SQUARE_SIZE)) && (pixel_x_i <= (7*SQUARE_SIZE)) && (pixel_y_i >= SQUARE_SIZE) && (pixel_y_i <= (2*SQUARE_SIZE)))
								 //FILA 3
								 || ((pixel_x_i >= SQUARE_SIZE) && (pixel_x_i <= (2*SQUARE_SIZE)) && (pixel_y_i >= (2*SQUARE_SIZE)) && (pixel_y_i <= (3*SQUARE_SIZE)))
								 || ((pixel_x_i >= (3*SQUARE_SIZE)) && (pixel_x_i <= (4*SQUARE_SIZE)) && (pixel_y_i >= (2*SQUARE_SIZE)) && (pixel_y_i <= (3*SQUARE_SIZE)))
								 || ((pixel_x_i >= (5*SQUARE_SIZE)) && (pixel_x_i <= (6*SQUARE_SIZE)) && (pixel_y_i >= (2*SQUARE_SIZE)) && (pixel_y_i <= (3*SQUARE_SIZE)))
								 || ((pixel_x_i >= (7*SQUARE_SIZE)) && (pixel_x_i <= (8*SQUARE_SIZE)) && (pixel_y_i >= (2*SQUARE_SIZE)) && (pixel_y_i <= (3*SQUARE_SIZE)))
								 //FILA 4
								 || ((pixel_x_i >= 0) && (pixel_x_i <= SQUARE_SIZE) && (pixel_y_i >= (3*SQUARE_SIZE)) && (pixel_y_i <= (4*SQUARE_SIZE)))
							    || ((pixel_x_i >= (2*SQUARE_SIZE)) && (pixel_x_i <= (3*SQUARE_SIZE)) && (pixel_y_i >= (3*SQUARE_SIZE)) && (pixel_y_i <= (4*SQUARE_SIZE)))
								 || ((pixel_x_i >= (4*SQUARE_SIZE)) && (pixel_x_i <= (5*SQUARE_SIZE)) && (pixel_y_i >= (3*SQUARE_SIZE)) && (pixel_y_i <= (4*SQUARE_SIZE)))
								 || ((pixel_x_i >= (6*SQUARE_SIZE)) && (pixel_x_i <= (7*SQUARE_SIZE)) && (pixel_y_i >= (3*SQUARE_SIZE)) && (pixel_y_i <= (4*SQUARE_SIZE)))
								 //FILA 5
								 || ((pixel_x_i >= SQUARE_SIZE) && (pixel_x_i <= (2*SQUARE_SIZE)) && (pixel_y_i >= (4*SQUARE_SIZE)) && (pixel_y_i <= (5*SQUARE_SIZE)))
								 || ((pixel_x_i >= (3*SQUARE_SIZE)) && (pixel_x_i <= (4*SQUARE_SIZE)) && (pixel_y_i >= (4*SQUARE_SIZE)) && (pixel_y_i <= (5*SQUARE_SIZE)))
								 || ((pixel_x_i >= (5*SQUARE_SIZE)) && (pixel_x_i <= (6*SQUARE_SIZE)) && (pixel_y_i >= (4*SQUARE_SIZE)) && (pixel_y_i <= (5*SQUARE_SIZE)))
								 || ((pixel_x_i >= (7*SQUARE_SIZE)) && (pixel_x_i <= (8*SQUARE_SIZE)) && (pixel_y_i >= (4*SQUARE_SIZE)) && (pixel_y_i <= (5*SQUARE_SIZE)))
								 //FILA 6
								 ||((pixel_x_i >= 0) && (pixel_x_i <= SQUARE_SIZE) && (pixel_y_i >= (5*SQUARE_SIZE)) && (pixel_y_i <= (6*SQUARE_SIZE)))
							    || ((pixel_x_i >= (2*SQUARE_SIZE)) && (pixel_x_i <= (3*SQUARE_SIZE)) && (pixel_y_i >= (5*SQUARE_SIZE)) && (pixel_y_i <= (6*SQUARE_SIZE)))
								 || ((pixel_x_i >= (4*SQUARE_SIZE)) && (pixel_x_i <= (5*SQUARE_SIZE)) && (pixel_y_i >= (5*SQUARE_SIZE)) && (pixel_y_i <= (6*SQUARE_SIZE)))
								 || ((pixel_x_i >= (6*SQUARE_SIZE)) && (pixel_x_i <= (7*SQUARE_SIZE)) && (pixel_y_i >= (5*SQUARE_SIZE)) && (pixel_y_i <= (6*SQUARE_SIZE)))
								 //FILA 7
								 || ((pixel_x_i >= SQUARE_SIZE) && (pixel_x_i <= (2*SQUARE_SIZE)) && (pixel_y_i >= (6*SQUARE_SIZE)) && (pixel_y_i <= (7*SQUARE_SIZE)))
								 || ((pixel_x_i >= (3*SQUARE_SIZE)) && (pixel_x_i <= (4*SQUARE_SIZE)) && (pixel_y_i >= (6*SQUARE_SIZE)) && (pixel_y_i <= (7*SQUARE_SIZE)))
								 || ((pixel_x_i >= (5*SQUARE_SIZE)) && (pixel_x_i <= (6*SQUARE_SIZE)) && (pixel_y_i >= (6*SQUARE_SIZE)) && (pixel_y_i <= (7*SQUARE_SIZE)))
								 || ((pixel_x_i >= (7*SQUARE_SIZE)) && (pixel_x_i <= (8*SQUARE_SIZE)) && (pixel_y_i >= (6*SQUARE_SIZE)) && (pixel_y_i <= (7*SQUARE_SIZE)))
								 //FILA 8
								 ||((pixel_x_i >= 0) && (pixel_x_i <= SQUARE_SIZE) && (pixel_y_i >= (7*SQUARE_SIZE)) && (pixel_y_i <= (8*SQUARE_SIZE)))
							    || ((pixel_x_i >= (2*SQUARE_SIZE)) && (pixel_x_i <= (3*SQUARE_SIZE)) && (pixel_y_i >= (7*SQUARE_SIZE)) && (pixel_y_i <= (8*SQUARE_SIZE)))
								 || ((pixel_x_i >= (4*SQUARE_SIZE)) && (pixel_x_i <= (5*SQUARE_SIZE)) && (pixel_y_i >= (7*SQUARE_SIZE)) && (pixel_y_i <= (8*SQUARE_SIZE)))
								 || ((pixel_x_i >= (6*SQUARE_SIZE)) && (pixel_x_i <= (7*SQUARE_SIZE)) && (pixel_y_i >= (7*SQUARE_SIZE)) && (pixel_y_i <= (8*SQUARE_SIZE)));
	
	assign square_white_on = square_white;
	assign square_black_on = square_black;
	
	assign square_rgb_o = (square_white_on || square_black_on) ? ((square_white_on)? 8'b11111111 : 
													((square_black_on) ? 8'b00000000 : 8'b11000000)) : 8'b11000000;

endmodule
